function [ correctedIm magnitudeCorrection  ] = runUniformBackgroundCorrection...
    ( im, loPercentile, loPercentileFraction )

nonZeroImVals = im(im~=0);
hiPercentile = 100 - loPercentile;

loPercentileVal = loPercentileFraction*prctile(nonZeroImVals,loPercentile);
hiPercentileVal = prctile(nonZeroImVals,hiPercentile);

correctedIm = im;
correctedIm(correctedIm < loPercentileVal) = loPercentileVal;
correctedIm(correctedIm > hiPercentileVal) = hiPercentileVal;

% correctedIm = (correctedIm - loPercentileVal)/(hiPercentileVal - loPercentileVal);

% Renormalize Images
correctedIm = (correctedIm - loPercentileVal)/(1 - 2*loPercentileVal);
magnitudeCorrection = loPercentileVal;

end

